/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "sle_adapter_hdi.h"
#include "sle_host_hdi.h"
#include "sle_announce_hdi.h"
#include "sle_seek_hdi.h"
#include "sle_connect_hdi.h"
#include "sle_ssap_client_hdi.h"
#include "sle_ssap_server_hdi.h"
#include "sle_hal_errcode.h"
#include "sle_hilog.h"


SleHdiErrorCode SleInitHdiAdapter(SleHdiOpts* opts)
{
    SLE_LOGD("SleInitHdiAdapter start");
    SleHdiErrorCode ret = SLE_HDI_ERRCODE_FAIL;
    ret = GetSleHostHdiOpts(opts->hostOpts);
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "GetSleHostHdiOpts");
    ret = GetSleAnnounceHdiOpts(opts->announceOpts);
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "GetSleAnnounceHdiOpts");
    ret = GetSleSeekHdiOpts(opts->seekOpts);
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "GetSleSeekHdiOpts");
    ret = GetSleConnectHdiOpts(opts->connectOpts);
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "GetSleConnectHdiOpts");
    ret = GetSleSsapcHdiOpts(opts->ssapcOpts);
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "GetSleSsapcHdiOpts");
    ret = GetSleSsapsHdiOpts(opts->ssapsOpts);
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "GetSleSsapsHdiOpts");
    ret = InitCallbackAdapter();
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "RegisterCallbackAdapter");
    SLE_LOGD("SleInitHdiAdapter end");
    return SLE_HDI_ERRCODE_SUCC;
}

SleHdiErrorCode SleHdiInitOpts(SleHdiOpts* hdiOpts)
{
    SleHdiErrorCode ret = SLE_HDI_ERRCODE_FAIL;
    static SleHostHdiOpts hostHdiOpts;
    static SleAnnounceHdiOpts announceHdiOpts;
    static SleSeekHdiOpts seekHdiOpts;
    static SleConnectHdiOpts connectHdiOpts;
    static SleSsapcHdiOpts ssapcHdiOpts;
    static SleSsapsHdiOpts ssapsHdiOpts;
    static SleHdiOpts opts = {
        .hostOpts = &hostHdiOpts,
        .announceOpts = &announceHdiOpts,
        .seekOpts = &seekHdiOpts,
        .connectOpts = &connectHdiOpts,
        .ssapcOpts = &ssapcHdiOpts,
        .ssapsOpts = &ssapsHdiOpts,
    };
    ret = SleInitHdiAdapter(&opts);
    SLE_ASSERT_AND_RETURN_RET_LOG(ret == SLE_HDI_ERRCODE_SUCC, ret, "SleInitHdiAdapter");
    memcpy(hdiOpts, &opts, sizeof(SleHdiOpts));
    return SLE_HDI_ERRCODE_SUCC;
}